package com.ssy.lingxi.settle.accounts.model.constant;

import com.ssy.lingxi.common.language.LanguageHolder;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 结算状态枚举
 * @author 伍将
 * @date 2020/10/23
 * @version 2.0.0
 */
public enum SettlementStatusEnum {

    ALL(0, "所有结算状态"),
    /**
     * 待对账(确认账目完成)
     */
    TO_BE_ACCOUNT_COMPLETE(1, "待对账"),
    /**
     * 待付款
     */
    TO_BE_PAY(2, "待付款"),
    /**
     * 待收款
     */
    TO_BE_RECEIPT(3, "待收款"),
    /**
     * 已完成
     */
    COMPLETE(4, "已完成");

    private final Integer code;
    private final String message;

    SettlementStatusEnum(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Integer getCode() {
        return code;
    }

    public String getMessage() {
        return LanguageHolder.getName(this.getDeclaringClass(), this.getCode());
    }

    public static String getMessage(Integer code) {
        return Arrays.stream(SettlementStatusEnum.values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(ALL).getMessage();
    }

    public static SettlementStatusEnum getEnum(Integer code) {
        return Arrays.stream(SettlementStatusEnum.values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(ALL);
    }

    /**
     * 判断是否已支付.(3:待收款,4:已完成)
     * @param code
     * @return
     */
    public static boolean isPaied(Integer code){
        List<SettlementStatusEnum> collect = Stream.of(TO_BE_RECEIPT, COMPLETE).collect(Collectors.toList());
        SettlementStatusEnum settlementStatusEnum = collect.stream().filter(o -> o.getCode().equals(code)).findFirst().orElse(null);
        return settlementStatusEnum!=null;
    }
}
